package com.shuoyue.adven;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int space;
    private boolean useside = true;

    public SpacesItemDecoration(int space) {
        this.space = space;
    }

    public SpacesItemDecoration(int space, boolean useside) {
        this.space = space;
        this.useside = useside;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        if (useside) {
            outRect.left = space;
            outRect.right = space;
        }
        if (parent.getChildPosition(view) == 0)
            outRect.top = space;
        outRect.bottom = space;

        // Add top margin only for the first item to avoid double space between items

    }
}